@echo off & setlocal enabledelayedexpansion 
set /a "nrow=0"
set _key="HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\SERIALCOMM"
for /f "tokens=1,3 delims= " %%i in ('reg query !_key! ^| find /v "HKEY"') do (
   set "_device=%%i" & set "_com#=%%j" & echo/!_com#! !_device! 
    set /a "nrow+=1"
    echo !nrow!
)

::exit(0)
:: for get number only :: By using !_com_N:~3! to get [n]
for /f "tokens=3 delims= " %%c in ('reg query !_key! ^| find /v "HKEY"') do set "_com_N=%%c"&& echo/!_com_N:~3! = !_com_N!
setlocal disabledelayedexpansion

echo _com#=%_com#% _device=%_device%
echo %nrow%

if %nrow% NEQ 1 (
    goto FAIL_COM
)

if not exist .\qrcode goto FAIL_CODE

:FAIL_COM
echo _com#=%_com#% _device=%_device%
echo COM count = %nrow%, need only one COM
pause 
::> /dev/null
goto FAIL_COM

:FAIL_CODE
echo not exist qrcode.txt
pause 
::# > /dev/null
goto FAIL_CODE

timeout 2

